#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>

int main()
{
    /*孤儿进程*/

    /*创建子进程*/
    pid_t pid = fork();
    if (pid < 0)
    {
        perror("fork error:");
        exit(-1);
    }
    else if (pid == 0)
    {
        /* 子进程 */
        int cnt = 1;
        while (cnt--)
        {
            std::cout << "i am child process " << std::endl;
            sleep(1);
        }
    }
    else
    {
        /* 父进程 */
        std::cout << "i am parent process end..." << std::endl;
        int cnt = 30;
        while (cnt--)
        {
            sleep(1);
        }
    }

    return 0;
}